<?php
$this->breadcrumbs = array(
    '主题管理' => array('/manage/topic/manage'),
    $model->isNewRecord ? '主题新建' : '主题更新',
);
$action = $model->isNewRecord ? 'create' : 'update?id=' . $model->id;

$exts = $model->topicExts;
$items = array();

foreach ($exts as $ext)
{
    $items[$ext->id] = $ext->getItemContent();
}



$this->widget('zii.widgets.jui.CJuiSortable',array(
    'id' => 'topic_sort',
    'items'=>$items,
    'htmlOptions'=>['class'=>'list-unstyled'],
    'itemTemplate' => '<li class="panel panel-info" id="{id}">{content}</li>',
    // additional javascript options for the JUI Sortable plugin
    'options'=>array(
        'delay'=>'100',
    ),
));




?>


<div class="col-xs-1">
    <?php
    $url = Yii::app()->getController()->createUrl("/manage/topic/sort", array("id" => $model->id));
    $this->widget('bootstrap.widgets.TbButton', array(
        'buttonType' => 'submit',
        'type' => 'primary',
        'label' => '确认修改',
        'htmlOptions' => array('href'=>$url,'class' => 'sort submit', 'style' => 'width:120px;margin:15px 400px;'),
    ));
    ?>
</div>

<script>
    $(function ($) {
        $(document).on('click', '.sort', function () {
            if (!confirm('确定修改?')) return false;
            var th = this;
            var afterDelete = function () {
            };
            var type = $(this).attr('type');
            var id = '';
            var data = {
                'Topic':{
                    "exts":[]
                }
            };
            $('.item_data').each(function () {
               data.Topic.exts.push({
                   'id': ($(this).attr('id')),
                   'type': ($(this).attr('type'))
               });
            });
            $.ajax({
                type: 'POST',
                data: data,
                url: $(this).attr('href'),
                ajaxUpdate: false,
                success: function (data) {
                    if (data == 'Success') {
                        alert('修改成功,请刷新');
                    } else {
                        alert(data);
                    }
                    afterDelete(th, true, data);
                },
                error: function (XHR) {
                    return afterDelete(th, false, XHR);
                }
            });

            return false;
        });
    });
</script>
